package org.m3;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


/**
 * Get Started!
 * @author yakovlev.yuriy@gmail.com
 * @author Dmitry Makeev
 */
public class Games extends Activity implements OnClickListener {
	private Button btnQuiz;
	private Button btnTwoCards;
	private Button btnPuzzle;
	private Button btnHome;
	private Dialog dialog;
    private Intent quiz;
    private Intent twoCards;
    private Intent puzzle;

	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        L10N.init(this.getResources());
        setContentView(R.layout.bg);
        
        initBtnQuiz();
        initBtnTwoCards();
        initBtnPuzzle();
        initBtnHome();
        
        getDialog().show();
	}

    @Override
	public void onClick(View arg0) {
    	if(arg0.equals(btnQuiz)) {
			startActivity(getQuiz());
    	} else if(arg0.equals(btnTwoCards)) {
    		startActivity(getTwoCards());
    	} else if(arg0.equals(btnPuzzle)) {
    		startActivity(getPuzzle());
    	} else if(arg0.equals(btnHome)) {
    		finish();
    	}
	}

	
	// PRIVATE METHODS

	private Dialog getDialog() {
		if(dialog == null) {
			dialog = new Dialog(this);
			dialog.setTitle("  " + getResources().getString(R.string.type_game));
	        dialog.setContentView(R.layout.game_menu);
		}
		return dialog;
	}
	
	private void initBtnQuiz() {
		if(btnQuiz == null) {
			btnQuiz = (Button) getDialog().findViewById(R.id.btnQuiz);
			btnQuiz.setTypeface(L10N.font);
			btnQuiz.setOnClickListener(this);
		}
	}
	
	private void initBtnTwoCards() {
		if(btnTwoCards == null) {
			btnTwoCards = (Button) getDialog().findViewById(R.id.btnTwoCards);
			btnTwoCards.setTypeface(L10N.font);
			btnTwoCards.setOnClickListener(this);
		}
	}

	private void initBtnPuzzle() {
		if(btnPuzzle == null) {
			btnPuzzle = (Button) getDialog().findViewById(R.id.btnPuzzle);
			btnPuzzle.setTypeface(L10N.font);
			btnPuzzle.setOnClickListener(this);
		}
	}
	
	private void initBtnHome() {
		if(btnHome == null) {
			btnHome = (Button) getDialog().findViewById(R.id.btnHome);
			btnHome.setTypeface(L10N.font);
			btnHome.setOnClickListener(this);
		}
	}

    private Intent getQuiz() {
    	if(quiz == null) {
    		quiz = new Intent(this, Quiz.class);
    	}
    	return quiz;
    }
    
    private Intent getTwoCards() {
    	if(twoCards == null) {
    		twoCards = new Intent(this, TwoCards.class);
    	}
    	return twoCards;
    }

    private Intent getPuzzle() {
    	if(puzzle == null) {
    		puzzle = new Intent(Games.this, Puzzle.class);
    	}
    	return puzzle;
    }

}
